package com.orange.notificationsummary.loader;

import java.util.List;

import com.orange.homescreen.pil.NotificationSummaryInterface;
import com.orange.homescreen.pil.PILInterfaceManager;
import com.orange.notificationsummary.EventTypeAndCount;
import com.orange.notificationsummary.R;
import com.orange.notificationsummary.SummaryActivity;
import com.orange.notificationsummary.event.pil.defaultimpl.BaseEvent;
import com.orange.notificationsummary.utils.LogHelper;

public class MissCallLoader extends BasicLoader {
	private static final String	TAG	= "MissCallLoader";

	private SummaryActivity		mHostActivity;
	private List<BaseEvent>		mEventList;

	public MissCallLoader(SummaryActivity hostActivity) {
		super("MissCallLoader", LoaderController.MISSCALL_LOADER);
		this.mHostActivity = hostActivity;
	}

	@Override
	protected void loadData() {
		NotificationSummaryInterface notifyInterface = (NotificationSummaryInterface) PILInterfaceManager
				.getInterface(NotificationSummaryInterface.class);
		this.mEventList = notifyInterface.getAllMissedCallEvent(mHostActivity);
	}

	@Override
	protected void showData() {
		LogHelper.i(TAG, "showData. ");
		this.mHostActivity.setEventData(mEventList,
				this.getEventTypeAndCount(), this.getLoaderType());
	}

	@Override
	protected EventTypeAndCount getEventTypeAndCount() {
		// TODO Auto-generated method stub
		int event_count = 0;
		long event_lasttime = 0;
		if (mEventList != null) {
			event_count = mEventList.size();
		}
		if (event_count > 0) {
			event_lasttime = mEventList.get(0).event_date;
		}
		EventTypeAndCount evnet = new EventTypeAndCount(event_lasttime,
				mHostActivity.getResources().getDrawable(
						R.drawable.icon_missed_call_24), event_count,
				mHostActivity);
		return evnet;
	}
}
